pub mod dept;
pub mod dict;
pub mod excel;
pub mod menu;
pub mod monitor;
pub mod post;
pub mod role;
pub mod swagger;
pub mod user;

use crate::middleware::auth_token;
use crate::websocket::{excel_connected, user_connected};
use hypers::prelude::{Config, OpenApi, Router, SwaggerUi};

pub fn router(r: &mut Router) {
    // r.hook(
    //     auth_token,
    //     vec!["/*"],
    //     vec![
    //         "/chat",
    //         "/tool/excel/connected",
    //         "/captchaImage",
    //         "/login",
    //         "/swagger_ui/*",
    //         "/swaggerLogin",
    //         "/api-doc/openapi.json",
    //     ],
    // );
    let doc: OpenApi = OpenApi::new("后台接口文档", "0.2.1");
    r.openapi("/api-doc/openapi.json", doc);
    r.push(user::Base)
        .push(user::User)
        .push(role::Role)
        .push(post::Post)
        .push(monitor::Monitor)
        .push(menu::Menu)
        .push(excel::Excel)
        .push(dict::Dict)
        .push(dept::Dept);

    r.ws("/chat", user_connected)
        .ws("/tool/excel/connected", excel_connected);

    // r.post("/swaggerLogin", swagger::swagger_login);
    // swagger.hook(swagger::auth_token, None, None);
    let swagger_ui = SwaggerUi::new(Config::new(r.urls.clone()));
    r.get("/swagger_ui/*", swagger_ui);
}
